package dtos;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;



public class PersonalizedTPDTO {
	
	private int travelID;

	private Date dateOfDeparture;

	private Date dateOfReturn;

	private int nomberOfPeople;

	private List<InvitationDTO> invitations;

	private List<ExcursionDTO> excursions;

	private HotelDTO hotelBean;

	private MeanOfTransportationDTO meanOfTransportation1;

	private MeanOfTransportationDTO meanOfTransportation2;

	private UserDTO user;
	
	private boolean confirmed;
	
	private List<ExcursionPersTPDTO> excursionPersTps;
	


	public PersonalizedTPDTO() {
		this.excursionPersTps = new LinkedList<ExcursionPersTPDTO>();
	}

	public int getTravelID() {
		return this.travelID;
	}

	public void setTravelID(int travelID) {
		this.travelID = travelID;
	}

	public Date getDateOfDeparture() {
		return this.dateOfDeparture;
	}

	public void setDateOfDeparture(Date dateOfDeparture) {
		this.dateOfDeparture = dateOfDeparture;
	}

	public Date getDateOfReturn() {
		return this.dateOfReturn;
	}

	public void setDateOfReturn(Date dateOfReturn) {
		this.dateOfReturn = dateOfReturn;
	}

	public int getNomberOfPeople() {
		return this.nomberOfPeople;
	}

	public void setNomberOfPeople(int nomberOfPeople) {
		this.nomberOfPeople = nomberOfPeople;
	}

	public List<InvitationDTO> getInvitations() {
		return this.invitations;
	}

	public void setInvitations(List<InvitationDTO> invitations) {
		this.invitations = invitations;
	}

	public InvitationDTO addInvitation(InvitationDTO invitation) {
		getInvitations().add(invitation);
		invitation.setPersonalizedTp(this);

		return invitation;
	}

	public InvitationDTO removeInvitation(InvitationDTO invitation) {
		getInvitations().remove(invitation);
		invitation.setPersonalizedTp(null);

		return invitation;
	}

	public List<ExcursionDTO> getExcursions() {
		return this.excursions;
	}

	public void setExcursions(List<ExcursionDTO> excursions) {
		this.excursions = excursions;
	}

	public HotelDTO getHotelBean() {
		return this.hotelBean;
	}

	public void setHotelBean(HotelDTO hotelBean) {
		this.hotelBean = hotelBean;
	}

	public MeanOfTransportationDTO getMeanOfTransportation1() {
		return this.meanOfTransportation1;
	}

	public void setMeanOfTransportation1(MeanOfTransportationDTO meanOfTransportation1) {
		this.meanOfTransportation1 = meanOfTransportation1;
	}

	public MeanOfTransportationDTO getMeanOfTransportation2() {
		return this.meanOfTransportation2;
	}

	public void setMeanOfTransportation2(MeanOfTransportationDTO meanOfTransportation2) {
		this.meanOfTransportation2 = meanOfTransportation2;
	}

	public UserDTO getUser() {
		return this.user;
	}

	public void setUser(UserDTO user) {
		this.user = user;
	}

	
	public boolean isValid()
	{
		return ((!(dateOfDeparture==null))&& (!(dateOfReturn==null)) && (nomberOfPeople > 0) && (!(hotelBean==null)) && (!(meanOfTransportation1==null)) && (!(meanOfTransportation2==null)));
	}

	public int getPrice(){
		int numberNights = daysBetween(dateOfDeparture, dateOfReturn);
		int price = this.hotelBean.getCost()*(numberNights) + this.getMeanOfTransportation1().getCost() + this.getMeanOfTransportation2().getCost();
		for (ExcursionDTO e : excursions){
			price = price + e.getCost();
		}
		return price;
	}
	
	public int daysBetween(Date d1, Date d2){
		 return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
		 }
	
	public String getExcursionsList(){
		
	
		String list = "***";
		SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
		for (ExcursionPersTPDTO ep : this.excursionPersTps){
			ExcursionDTO e = ep.getExcursion();
			if (ep.getDate() != null){
				list = list + e.getName()+", meeting at "+e.getMeetingPlace()+" at "+e.getMeetingTime()+" the "+formater.format(ep.getDate())+"***";
				
			}
			else{
				list = list + e.getName()+", meeting at "+e.getMeetingPlace()+" at "+e.getMeetingTime()+"***";
				
			}
		}
		
		return list;
		
	}
	
	public String getDateOfReturnFormat() {
		SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
		return formater.format(this.dateOfReturn);
	}
	
	public String getDateOfDepartureFormat() {
		SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
		return formater.format(this.dateOfDeparture);
	}
	
	public boolean getConfirmed(){
		return confirmed;
	}
	
	public void setConfirmed(boolean confirmed){
		this.confirmed = confirmed;
	}
	
	public String getConfirmation(){
		if (confirmed){
			return "Confirmed";
		}
		else{
			return "Not Confirmed";
		}
	}
	
	public List<ExcursionPersTPDTO> getExcursionPersTps() {
		return this.excursionPersTps;
		
	}

	public void setExcursionPersTps(List<ExcursionPersTPDTO> excursionPersTps) {
		this.excursionPersTps = excursionPersTps;
	}
	
	
}
